package com.lfg.leetcode.leetcode0;


public class No35SearchInsert {


    public static int searchInsert(int[] nums, int target) {
        if (nums.length == 0) {
            return 0;
        }
        int i = 0;
        int j = nums.length - 1;
        while (i <= j) {
            int middle = (i + j) / 2;
            if (target == nums[middle]) {
                return middle;
            } else if (target < nums[middle]) {
                j = middle - 1;
            } else if (target > nums[middle]) {
                i = middle + 1;
            }
        }
        return i;
    }


    public static void main(String[] args) {
//        int ret = search(new int[]{9,10,11,0,1,2, 3,4,5,6,7,8},1);
        int ret = searchInsert(new int[]{5, 16, 27, 38, 49, 510}, 318);
        System.out.println(ret);
    }
}

